package com.example.eventexample.route


import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import com.example.eventexample.R
import com.example.eventexample.bean.TestBBeanA
import com.example.eventexample.bean.TestBBeanB
import com.example.eventexample.eventbus.EventTestB
import com.zee.annotation.ActivityTag
import com.zee.log.ZLog
import com.zee.utils.UIUtils
import com.zee.utils.ZEventBusUtils
import kotlinx.android.synthetic.main.activity_eventbus_second.*
import org.greenrobot.eventbus.*
import org.greenrobot.eventbus.adapter.EventBusPostAdapter

@ActivityTag(name = "secondTag", module = "dier", keyWords = "登录成功判断")
class EventBusSecondActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        ZEventBusUtils.register(this)
        TestBBeanA()
        TestBBeanB()
        setContentView(R.layout.activity_eventbus_second)
        id_second_value.text = "获得值位： ${intent.getIntExtra("value", 0)}";
        val value = intent.getIntExtra("value", 0)
        ZLog.i("value------>>$value")
        eventBus_A.setOnClickListener {
            ZEventBusUtils.post(10, "statickTag", object : EventBusPostAdapter() {})
        }
        eventBus_B.setOnClickListener {
            //            startActivity(Intent(this, EvenBusCActivity::class.java))
        }
        EventTestA()
        EventTestB()
    }

    @SubscribeMainThread(tag = "statickTag")
    fun overEventBusA(a: Int) {
        UIUtils.showToastShort(a.toString() + "tag1")
//        ZLog.i("测试1")
    }

    @SubscribeMainThread(tag = "statickTag")
    fun overEventBusB(a: Int) {
        UIUtils.showToastShort(a.toString() + "tagb")
        val value = 10;

//        ZLog.i("测试2"+(value/0))
    }

    @SubscribeMainThread(tag = "statickTag", sticky = true)
    fun overEventBusD(a: Int) {
        UIUtils.showToastShort(a.toString() + "overEventBusD-->stickyTag2")
    }

    @SubscribeMainThread(tag = "stickyTag", sticky = true)
    fun overEventBusC(a: Int) {
        UIUtils.showToastShort(a.toString() + "overEventBusCstickyTag")
    }

    override fun onDestroy() {
        super.onDestroy()
        ZEventBusUtils.unregister(this)
        EventBus.getDefault().printCurAllSubscribers()
    }
}
